<template>
  <div>
    <div class="top">
      <el-input
        v-model="query"
        placeholder="输入商品具体查询"
        style="width: 200px; line-height: 50px; border-radius: 30px"
        clearable
        @clear="getorders(pagenum, pagesize)"
      ></el-input>
      <el-button
        type="primary"
        round
        icon="el-icon-search"
        @click="getorders(pagenum, pagesize)"
        >搜索</el-button
      >
    </div>
    <template>
      <el-table :data="tableData" style="width: 100%; line-height: 30px">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form
              label-position="left"
              inline
              class="demo-table-expand"
              style="width: 50%"
            >
              <el-form-item label="商品名称">
                <span>{{ props.row.name }}</span>
              </el-form-item>
              <el-form-item label="数量">
                <span>{{ props.row.goods_number }}</span>
              </el-form-item>
              <el-form-item label="商品 ID">
                <span>{{ props.row.goods_id }}</span>
              </el-form-item>
              <el-form-item label="重量">
                <span>{{ props.row.goods_weight }}</span>
              </el-form-item>

              <el-form-item label="是否是热销品">
                <span>{{ props.row.is_promote }}</span>
              </el-form-item>
              <el-form-item label="商品价格">
                <span>{{ props.row.goods_price }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="商品 ID" prop="goods_id" width="130px">
        </el-table-column>
        <el-table-column label="商品名称" prop="goods_name"> </el-table-column>
        <el-table-column label="商品价格" prop="goods_price" width="170px">
        </el-table-column>
        <el-table-column label="添加时间" prop="add_time">
          <span
            ><template slot-scope="scope">{{
              scope.add_time | moment
            }}</template></span
          >
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <el-button size="mini" icon="el-icon-edit" type="info"
            >修改信息</el-button
          >
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            title="删除商品"
          ></el-button>
        </el-table-column>
      </el-table>
      <!-- 分页按钮 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </template>
  </div>
</template>

<script>
export default {
  name: "VueCategories",

  data() {
    return {
      tableData: [],
      pagesize: 10,
      pagenum: 1,
      total: 1,
      query: "",
    };
  },

  mounted() {
    this.getorders(1, this.pagesize);
  },

  methods: {
    async getorders(pagenum = 1, pagesize = 3) {
      var { data } = await this.$axios.get(
        `/goods?pagenum=${pagenum}&pagesize=${pagesize}`,
        { params: { query: this.query } }
      );
      if (data.meta.status == 200) {
        console.log(data);
        this.tableData = data.data.goods;
        this.total = data.data.total;
        this.pagenum = data.data.pageNum;
      }
    },
    async handleSizeChange(pagesize) {
      this.pagesize = pagesize;
      this.getorders(1, pagesize);
    },

    async handleCurrentChange(pagenum) {
      this.getorders(pagenum, this.pagesize);
    },
  },
};
</script>

<style lang="css" >
.top {
  display: flex;
  height: 50px;
  /* border: rgb(233, 67, 67) solid 1px; */
  border-radius: 30px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>